<?php

class serviceModel extends commonModel {

    public function __construct() {
        $this->initialDB();
    }

    public function uploadDir($file_name) {
        $file_dir = Data::$_pic_path.$file_name;
        $doc_dir = FileUpload::setUploaddir('index.php', $file_dir); // C:/wamp/www/sample/
        $dir = $doc_dir . $file_dir;
        return $dir;
    }

    public function getNewsCount(){
        $sql = "SELECT * FROM news  WHERE (status = 9 OR status = 7 OR status = 3) AND riders_tel = '{$_SESSION['riders']['tel']}' AND ico = 1 AND isdeleted = 0";
        $res = $this->getAny($sql);
        if (!empty($res)) {
            while ($row = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
                $rsp_list[] = $row;
            }
        }
        $newsCount = count($rsp_list);
        return $newsCount;
    }


    public function CheckRider($data){
        $sql = "SELECT status,remark FROM riders  WHERE tel = '{$data['mobile']}' AND isdeleted = 0";
        $res = $this->getAny($sql);
        $rsp_list = [];
        if (!empty($res)) {
            while ($row = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
                $rsp_list[] = $row;
            }
        }
        $res = [];
        if($rsp_list && count((array) $rsp_list) > 0){
            $res['result']['status'] = 1;
            $res['result']['msg'] = '';
            $res['result']['data'] = $rsp_list[0];
        }else{
            $res['result']['status'] = 0;
            $res['result']['msg'] = '';
        }
        return $res;
    }

    public function GetStores($data){
        $sql = "SELECT * FROM xd_store WHERE (status = 2 OR status = 4 OR status = 5) AND area = ".$data["area"];
        $store = $this->getAny($sql);
        if (!empty($store)) {
            while ($Stores = mysqli_fetch_array($store, MYSQLI_ASSOC)) {
                $row[] = $Stores;
            }
        }
        $res = [];
        if($row){
            $area = [];
            foreach ($row as $k=>$r){
//                $area[$k][$r['store_id']] = $r['storename'];
                $area[$k]['id'] = $r['store_id'];
                $area[$k]['name'] = $r['storename'];
            }
            $res['result']['status'] = 1;
            $res['result']['msg'] = '';
            $res['result']['list'] = $area;
        }else{
            $res['result']['status'] = 0;
            $res['result']['msg'] = '';
        }
        return $res;
    }

    public function checkRiders($name,$nickName){
        $sql = "SELECT id FROM riders  WHERE (name = '$name' OR username = '$nickName') AND isdeleted = 0";
        $res = $this->getAny($sql);
        $rsp_list = [];
        if (!empty($res)) {
            while ($row = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
                $rsp_list[] = $row;
            }
        }
        if($rsp_list && count($rsp_list) > 0){
            return true;
        }else{
            return false;
        }
    }
    public function couponshareexecute($express_id,$SessionTel)
    {

        $result = $this->db->couponshareexecute($express_id,$SessionTel);

        return $result;
    }
}
